<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js动画</title>
  <script src="./vue.js"></script>
  <script src="./velocity.js"></script>
</head>
<body>
  <div id="root">
    <transition name="fade"
        @before-enter="handleBeforeEnter"
        @enter="handleEnter"
        @after-enter="handleAfterEnter"
        @before-leave="handleBeforeLeave"
        @leave="handleLeave"
        @after-leave="handleAfterLeave"
    >
      <div v-show="show">
        hello world
      </div>
    </transition>
    <button @click="handleClick">toggle</button>
  </div>

  <script>
    // js动画， 通过给transition标签绑定事件
    // befor@before-enter="handleBeforeEnter"
    // @enter="handleEnter"
    // @after-enter="handleAfterEnter"
    var vm = new Vue({
      el: '#root',
      data: {
        show: true
      },
      methods: {
        handleClick: function() {
          this.show = !this.show
        },
        handleBeforeEnter: function(el) {
          el.style.opacity = 0;
        },
        handleEnter: function(el, done) {
          Velocity(el, {
            opacity: 1
          }, {
            duration: 1000,
            complete: done
          })
        },
        handleAfterEnter: function(el) {
          console.log('入场动画结束');
        },
        handleBeforeLeave: function(el) {
          el.style.opacity = 1
        },
        handleLeave: function(el, done) {
          Velocity(el, {opacity: 0}, {duration: 1000, complete: done})
        },
        handleAfterLeave: function(el) {
          console.log('退场动画结束');
        } 

        // handleBeforeEnter: function(el) { // el指要执行动画的元素
        //   // console.log('beforEnter')
        //   el.style.color = "red"
        // },
        // handleEnter: function(el, done) { // 入场动画，参数包含一个回调函数，动画执行完调用
        //   setTimeout(function() {
        //     el.style.color = "blue"
        //   }, 2000);

        //   setTimeout(function() { 
        //     done();
        //   }, 4000)
        // },
        // handleAfterEnter: function(el) { // 动画结束
        //   el.style.color = "pink"
        // }
      }

    })
  </script>
</body>
</html>